from drf_haystack.serializers import HaystackSerializer
from rest_framework import serializers
from new_list.search_indexes import BloIndex

from .models import Blogs


class BlogsModelSerializers(serializers.ModelSerializer):
    class Meta:
        model = Blogs
        fields = ('id','title','digest','index_image_url','get_time','clicks','source')


class CatIndexSerializer(HaystackSerializer):  # HaystackSerializer的序列化器
    """
    新闻索引结果数据序列化器
    """
    object = BlogsModelSerializers(read_only=True)

    class Meta:
        index_classes = [BloIndex]
        fields = ('text', 'object')